<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="05-从WebStorage取数据.html" method="get">
    <input type="text" name="account">
    <button>提交</button>
</form>
<script>
    function t1() {
        // sessionStorage
        // localStorage
        sessionStorage.setItem("account", "abc");
        sessionStorage.setItem("password", "123");
        // 创建对象
        let obj = {name: "张三", age: 20};
        sessionStorage.setItem("obj", JSON.stringify(obj));
        let books = [
            {id: 1, name: 'Java从入门到放弃', price: 80, createDate: '2020-07-01', count: 1},
            {id: 2, name: 'Vue从入门到放弃', price: 90, createDate: '2020-07-02', count: 1},
            {id: 3, name: 'Mysql从入门到放弃', price: 100.01, createDate: '2020-07-03', count: 1},
            {id: 4, name: '啥都从入门到放弃', price: 70.0001, createDate: '2020-07-04', count: 1},
            {id: 5, name: 'JavaScript从入门到放弃', price: 60.00, createDate: '2020-07-04', count: 1},
            {id: 6, name: 'JavaScript从入门到放弃', price: 50.00, createDate: '2020-07-04', count: 1}
        ];
        sessionStorage.setItem("books", JSON.stringify(books));

        // 如何取数据
        console.log(sessionStorage.getItem("account"));
        console.log(sessionStorage.getItem("password"));
        let objJson = JSON.parse(sessionStorage.getItem("obj"));
        console.log(sessionStorage.getItem("obj"));
        console.log(objJson);
        console.log(objJson.name);
        let booksJson = JSON.parse(sessionStorage.getItem("books"));
        console.log(sessionStorage.getItem("books"));
        console.log(booksJson);
    }

</script>
</body>
</html>